/*
 * @Author: shengduiliang 1107722390@qq.com
 * @Date: 2024-05-04 13:41:50
 * @LastEditors: shengduiliang 1107722390@qq.com
 * @LastEditTime: 2024-05-04 21:24:25
 * @FilePath: /treasure/src/utils/Dialogts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import Taro from "@tarojs/taro";

interface AlertParams {
  title?: string;
  content: string;
  onConfirm?: () => void;
}

const alert = ({ title = '', content, onConfirm }: AlertParams) => {
  Taro.showModal({
    title,
    content,
    showCancel: false,
    success: () => {
      onConfirm && onConfirm();
    }
  })
}

interface ConfirmParams {
  title?: string;
  content: string;
  onConfirm?: () => void;
  onCancel?: () => void;
}

const confirm = ({ title = '', content, onConfirm, onCancel }: ConfirmParams) => {
  Taro.showModal({
    title,
    content,
    success: ({ confirm }) => {
      if (confirm) {
        onConfirm && onConfirm();
      } else {
        onCancel && onCancel();
      }
    }
  })
}

const toast = (title: string) => {
  Taro.showToast({
    title,
    icon: 'none',
    duration: 2000
  })
}

export default {
  alert,
  confirm,
  toast
}